Skip to content

[BUG] fix axis label overlap in plot_volume_source_estimates by using draw_idle()#13708

Open
Famous077 wants to merge 8 commits intomne-tools:mainfrom
Famous077:fix/volume-plot-axis-labels-blitting
Open

[BUG] fix axis label overlap in plot_volume_source_estimates by using draw_idle()#13708
Famous077 wants to merge 8 commits intomne-tools:mainfrom
Famous077:fix/volume-plot-axis-labels-blitting

Conversation

@Famous077
Copy link
Contributor

@Famous077 Famous077 commented Feb 28, 2026

This PR addresses axis label overlap and rendering artifacts observed
when navigating through time in plot_volume_source_estimates() by
replacing canvas.draw() with canvas.draw_idle().

Problem

When plotting volume source estimates, axis labels were mangled and
overlapping on the colorbar and y-axis of the time series plot.
The MRI and colorbar also appeared shifted relative to the black background.

Root Cause

canvas.draw() was being called after each click/keypress event in
_press() and _onclick(), causing blitting artifacts when combined
with nilearn's plotting functions.

Fix

Replaced canvas.draw() with canvas.draw_idle() in both _press()
and _onclick() functions in mne/viz/_3d.py. This lets matplotlib
schedule the redraw properly and avoids the rendering artifacts.

Changes

  • mne/viz/_3d.py: canvas.draw()canvas.draw_idle() in _press() and _onclick()
  • doc/changes/dev/13700.bugfix.rst: changelog entry
  • doc/changes/names.inc: added contributor name

@Famous077 Famous077 changed the title [BUG]: fix axis label overlap in plot_volume_source_estimates by using draw_idle() [BUG] fix axis label overlap in plot_volume_source_estimates by using draw_idle() Feb 28, 2026
@Famous077
Copy link
Contributor Author

All tests in mne/viz/tests/test_3d_mpl.py pass locally.
The 2 CI failures appear to be Azure Pipelines infrastructure
issues, unrelated to this change. Waiting for your review whenever you get a chance.

@larsoner
Copy link
Member

larsoner commented Mar 2, 2026

@Famous077 looks good! Did you use AI at all during the development of this PR, and if so, can you explain how / to what extent?

@Famous077
Copy link
Contributor Author

@Famous077 looks good! Did you use AI at all during the development of this PR, and if so, can you explain how / to what extent?

Yes, I did use AI. happy to be transparent about it. But, I used it as a research and debugging aid, mainly in areas that would have been too time-consuming to dig through alone, such as understanding the difference between canvas.draw() and canvas.draw_idle(), why calling draw() synchronously after every event causes blitting artifacts with nilearn, and clearing doubts about specific lines of code, but actual diagnosis, implementation, and testing were entirely my own.

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and AI usage seems okay to me, but we're actively debating this at the moment. I'll let @drammock merge if he's happy but maintainers might need to discuss further

@larsoner larsoner added this to the 1.12 milestone Mar 2, 2026
@drammock drammock enabled auto-merge (squash) March 2, 2026 18:07
@drammock drammock disabled auto-merge March 2, 2026 18:09
Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on second look:

  • the linked issue that will be auto-closed by this is unrelated (it's another of your own PRs)
  • can you link to an example in the docs where this label overlap is happening?
  • can you modify that example/tutorial that uses plot_volume_source_estimates (a linebreak/whitespace change is enough) so that the CI will run it, and we can see that the label overlap is fixed?

@Famous077
Copy link
Contributor Author

Famous077 commented Mar 2, 2026

Hi @drammock , Thank you for the review. I have addressed the following:

-Removed the incorrect issue reference from the PR description
-Renamed changelog to 13708.bugfix.rst
-Fixed the author name in the changelog

Regarding linking to an example in the docs , I searched through all examples and tutorials but could not find one that directly calls plot_volume_source_estimates. Could you point me to the specific example you had in mind so I can add a whitespace change to trigger CI to run it? Thank you for your guidance

@Famous077 Famous077 requested a review from drammock March 2, 2026 19:32
@drammock
Copy link
Member

drammock commented Mar 2, 2026

plot_volume_source_estimates is wrapped by the .plot() method of VolSourceEstimate and VolVectorSourceEstimate so in theory modifying this tutorial would make sense.

However, the PR description is still (wrongly) linking to #13700 (which isn't related to plot_volume_source_estimates) and a quick search of open issues yields nothing about the error you say is being fixed by this... so can you clarify how you even know that there's a problem to be fixed? Is it evident in one or more of the plots on that tutorial page? Or did you discover this locally while using the plot_volume_source_estimates function, or some other way? A screenshot of the problematic behavior (with & without the changes in this PR) is what I'm after. If you make the screenshots locally, please use one of our built-in datasets and include the code you used to generate the plots.

@Famous077
Copy link
Contributor Author

Hi @drammock , After further investigation, I can confirm the bug is reproducible locally
with nilearn 0.13.1 and matplotlib 3.10.8. The axis labels are mangled even
on the initial render (before any interaction), which suggests this is a
deeper compatibility issue between nilearn and matplotlib 3.10 rather than
a blitting issue.

Here is a screenshot showing the bug:
Screenshot 2026-03-03 125947

I've tried:

  1. canvas.draw() → canvas.draw_idle()
  2. layout="constrained" → layout="tight"

Could you point me in the right direction for the correct fix? Is this indeed a nilearn compatibility issue?

@Famous077 Famous077 requested a review from larsoner March 5, 2026 02:55
@larsoner
Copy link
Member

larsoner commented Mar 5, 2026

Could you point me in the right direction for the correct fix? Is this indeed a nilearn compatibility issue?

I don't know off hand (and would be surprised if @drammock did either), it will likely require some investigation and testing out of other possible solutions. Possibly a git bisect with nilearn to see when things broke could help, not sure

@Famous077
Copy link
Contributor Author

Could you point me in the right direction for the correct fix? Is this indeed a nilearn compatibility issue?

I don't know off hand (and would be surprised if @drammock did either), it will likely require some investigation and testing out of other possible solutions. Possibly a git bisect with nilearn to see when things broke could help, not sure

Hi @larsoner , what should i do to resolve this issue? Any suggestions .

@drammock
Copy link
Member

drammock commented Mar 5, 2026

what should i do to resolve this issue? Any suggestions .

did you try the prior suggestion:

Possibly a git bisect with nilearn to see when things broke could help

@drammock drammock marked this pull request as draft March 5, 2026 19:40
@Famous077 Famous077 marked this pull request as ready for review March 5, 2026 19:44
@Famous077
Copy link
Contributor Author

what should i do to resolve this issue? Any suggestions .

did you try the prior suggestion:

Possibly a git bisect with nilearn to see when things broke could help

Okay. After implementation I will reach out to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants